package ru.mcfr.oxygen.util;

import org.w3c.dom.Document;

/**
 * Created by IntelliJ IDEA.
 * User: ws
 * Date: 05.07.11
 * Time: 17:44
 * To change this template use File | Settings | File Templates.
 */
public class Starter {

    public String usage(int mode){
        String usageText = "run params:\n" +
                "     remove-id    remove all id attr from file\n" +
                "     fill-id      fill id attr in file\n" +
                "     remove-id|fill-id refill id attr in file";


        return usageText;
    }

    //run params:
    // remove-id    remove all id attr from file
    // fill-id      fill id attr in file
    // remove-id|fill-id refill id attr in file
    public static void main(String[] arg){
        doFile(arg[1], arg[0]);
    }

    public static void doFile(String fileName, String mode){
        try {
            Document doc = XmlTool.docFromFile(fileName);
            FillIDs filler = new FillIDs();
            if (mode.contains("remove-id"))
                filler.removeAllId(doc);

            if (mode.contains("fill-id"))
                filler.fillXML(doc);
            XmlTool.docToFile(doc, fileName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
